
/*
 *参数1，结构体
 *
 *
 *
 */
#include "myQueue.h"
#include "../_public.h"
void handle_client_request(qNode_st *conn){
	char buffer[1024] = {0};
    // 等待客户端发来的数据载体...
    int ret = recv(conn->fd, buffer, sizeof(buffer), 0);
    // 判断C与S是否断开连接
    if (ret <= 0) {
        if (ret == 0) {
            printf("Client disconnected.\n");
        } else {
            perror("recv");
        }
        conn->aliveStatus = 0;
        close(conn->fd);
        return;
    }

    uint32_t cmd_len;
	uint32_t name_len;
    uint32_t path_len;
    memcpy(&cmd_len, buffer, 4);
    cmd_len = ntohl(cmd_len);
    memcpy(&name_len, buffer + 4 + cmd_len, 4);
    name_len = ntohl(name_len);
	memcpy(&path_len, buffer + 8 + cmd_len + name_len, 4);
    path_len = ntohl(path_len);

    char command[256] = {0};
	char user_name[256] = {0};
    char virtual_path[256] = {0};
	char additional[256] = {0};

    memcpy(command, buffer + 4, cmd_len);
    memcpy(user_name, buffer + 8 + cmd_len, name_len);
	memcpy(virtual_path, buffer + 12 + cmd_len + name_len, path_len);

    if (ret > 12 + cmd_len + name_len + path_len) {
        uint32_t additional_len;
        memcpy(&additional_len, buffer + 12 + cmd_len + name_len + path_len, 4);
        additional_len = ntohl(additional_len);
        memcpy(additional, buffer + 16 + cmd_len + name_len + path_len, additional_len);
    }

    printf("Received command: %s\n", command); // 命令全路径
	printf("Received user_nam: %s\n", user_name);
    printf("Virtual path: %s\n", virtual_path);
    printf("Additional info: %s\n", additional);
    /*
	 *TODO:
	 *    拆出来cmd
	 *    
	 *    根据cmd执行对应的处理函数
     */
}